package git.soulbgm.common.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 全局异常处理程序
 *
 * @author SoulBGM
 * @date 2022/11/12 19:13
 */
@ResponseBody
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理
     *
     * @param e        异常
     * @param request  请求
     * @param response 响应
     * @throws IOException ioexception
     */
    @ExceptionHandler(value = Exception.class)
    public void handle(HttpServletRequest request, HttpServletResponse response, Exception e) throws IOException {
        e.printStackTrace();
        response.sendError(500, e.getMessage());
    }

}
